package com.qcby.service.Impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qcby.dao.StudentMapper;
import com.qcby.entity.PageBean;
import com.qcby.entity.Student;
import com.qcby.service.StudentService;

@Service("studentService")
public class StudentServicecImpl implements StudentService{

	@Autowired
	private StudentMapper studentMapper;
	
	@Override
	public int add(Student student) {
		return studentMapper.insert(student);
	}
	
	@Override
	public int del(Integer id) {
		return studentMapper.deleteByPrimaryKey(id);
	}
	
	@Override
	public int update(Student student) {
		return studentMapper.updateByPrimaryKey(student);
	}
	
	@Override
	public Student select(Integer id) {
		return studentMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Student> findListByStudent(Student student) {
		return studentMapper.findListByStudent(student);
	}

	@Override
	public Student logincheck(Student student) {
		return studentMapper.logincheck(student);
	}

	@Override
	public Student selectSec(Student student) {
		return studentMapper.selectReturnSec(student);
	}

	@Override
	public int selectCount() {
		// TODO Auto-generated method stub
		return studentMapper.selectCount();
	}

	@Override
	public PageBean<Student> findByPage(Integer currentPage) {
		
		HashMap<String,Object> map = new HashMap<String,Object>();
		PageBean<Student> pageBean = new PageBean<Student>();
		
	    //封装当前页数
        pageBean.setCurrPage(currentPage);
        
		//每页显示的数据
		int pageSize = 10;
		pageBean.setPageSize(pageSize);
		
		//封装总记录数
		int totalCount = studentMapper.selectCount();
		pageBean.setTotalCount(totalCount);
		
		//封装总页数
		double tc = totalCount;
        Double num =Math.ceil(tc/pageSize);//向上取整
        pageBean.setTotalPage(num.intValue());
      
		map.put("start",(currentPage-1)*pageSize);
		map.put("size", pageBean.getPageSize());
		//封装每页显示的数据
		List<Student> lists = studentMapper.findByPage(map);
		pageBean.setLists(lists);
		
		return pageBean;

	}
	
}
